package cn.jinjimi.app.entity.AppConfig;

import com.google.gson.annotations.SerializedName;

import cn.jinjimi.app.entity.LinkBean;
import cn.jinjimi.base.preference.PreferenceManager;
import cn.jinjimi.base.util.GsonUtils;
import cn.jinjimi.base.util.StringUtils;
import cn.jinjimi.app.bean.SharePrefKeys;

import java.util.ArrayList;
import java.util.List;

/**
 * 首页分类
 * @author zhenhua
 */
public class HomeCateList {
    @SerializedName("home_cates")
    public List<LinkBean> cates;

    public List<LinkBean> getCates() {
        return cates;
    }

    public HomeCateList(List<LinkBean> list) {
        this.cates = list;
    }
    public static List<LinkBean> fetchHomeCateList() {
        String data = PreferenceManager.getStringData(SharePrefKeys.PREF_CONFIG_CATE_LIST);
        if (StringUtils.isNotEmpty(data)) {
            HomeCateList list = GsonUtils.fromJson(data, HomeCateList.class);
            if (list != null) {
                return list.getCates();
            }
        }
        return new ArrayList<LinkBean>();
    }

    public static void save(List<LinkBean> list) {
        PreferenceManager.setData(SharePrefKeys.PREF_CONFIG_CATE_LIST, new HomeCateList(list));
    }
}
